/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package helloscala.practise.chapter13

import java.io.File
import java.io.FileReader
import java.io.IOException
import java.io.LineNumberReader

class FilePrinterScala(val file: File) {
  @throws(classOf[IOException])
  def print = {
    var reader: LineNumberReader = null
    try {
      reader = new LineNumberReader(new FileReader(file))
    } finally {
      if (reader != null)
        reader.close
    }
  }

  def loop(reader: LineNumberReader): Unit = {
    val line = reader.readLine
    if (line != null) {
      Console.print(format("%3d: %s\n", reader.getLineNumber, line))
      loop(reader) //tailed recursion
    }
  }
}
